package com.lance.shiro.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class UserStatus {

    public static String INACTIVE = "inactive";
    public static String ACTIVE = "active";
    public static String PENDING = "pending";
    public static String DRAFT = "draft";

    private static String regEx1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";

    private static String regEx2 = "^[A-Za-z\\d]+([-_.][A-Za-z\\d]+)*@([A-Za-z\\d]+[-.])+[A-Za-z\\d]{2,5}$";


    public static boolean validate(String status) {
        if (StringUtils.equals(status, INACTIVE) || StringUtils.equals(status, ACTIVE)
                || StringUtils.equals(status, PENDING) || StringUtils.equals(status, DRAFT)) {
            return true;
        }
        return false;
    }

    /**
     * 判断地址是否是邮箱
     *
     * @param string
     * @return
     */
    public static boolean isEmail(String string) {
        if (string == null) {
            return false;
        }
        Pattern p = Pattern.compile(regEx2);
        Matcher m = p.matcher(string);
        if (m.matches()) {
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) {
        String a = "dd";
        String b = "dd@123";
        String c = "dd@123.com";
        String d = "ipan_test1@163.com";
        System.out.println(isEmail(a));
        System.out.println(isEmail(b));
        System.out.println(isEmail(c));
        System.out.println(isEmail(d));
    }
}
